package com.cloudree.gllib.frament.cube;


import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;

import com.cloudree.gllib.BaseActivity;
import com.cloudree.gllib.frament.BaseFragment;
import com.cloudree.gllib.render.BlendingRender;
import com.cloudree.gllib.render.TriangleRender;
import com.cloudree.gllib.surface.BaseGLSurface;

/**
 * A simple {@link Fragment} subclass.
 */
public class BlendingFragment extends BaseFragment implements BaseActivity.OnTouchListener {
    private BlendingRender mRender;


    public BlendingFragment() {
        // Required empty public constructor
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        mSurface = new BaseGLSurface(getActivity());
        mRender = new BlendingRender();
        mSurface.setRenderer(mRender);
        ((BaseActivity) getActivity()).setTouchListener(this);
        return mSurface;
//        return inflater.inflate(R.layout.fragment_triangle, container, false);
    }

    @Override
    public boolean onTouch(MotionEvent event) {
        switch (event.getAction()) {
            case MotionEvent.ACTION_DOWN:
                mSurface.queueEvent(new Runnable() {
                    @Override
                    public void run() {
                        mRender.switchBlending();//must be invoked in gl thread
                    }
                });
                break;
        }
        return false;
    }

}
